function checkExecutableSkill_DayBreak(obj)  
{
	if (!obj) return false;

	local isUseSkill = obj.sq_IsUseSkill(SKILL_DAY_BREAK);
	if (isUseSkill) 
	{

		obj.getVar("GLOBAL_PARAMETER_CANCEL").set_vector(0,0);
		local pIntVec = sq_GetGlobalIntVector();
		sq_IntVectorClear(pIntVec);
		sq_IntVectorPush(pIntVec, 0);			
		obj.addSetStatePacket(STATE_DAY_BREAK , pIntVec,  STATE_PRIORITY_USER, false, "");
		return true;
	}
	return false;
}

function checkCommandEnable_DayBreak(obj)
{


	return true;
}


function preLoad_DayBreak(obj)
{
	local level = sq_GetSkillLevel(obj, SKILL_DAY_BREAK);
	if (level > 0)
	{

		createFristAnimationPooledObject(obj,
		"character/swordman/effect/animation/atdaybreak/daybreakattackbottom_00.ani");
		createFristAnimationPooledObject(obj,
		"character/swordman/effect/animation/atdaybreak/daybreakattackcover_01.ani");
		createFristAnimationPooledObject(obj,
		"character/swordman/effect/animation/atdaybreak/daybreakendcover_07.ani");
		createFristAnimationPooledObject(obj,
		"character/swordman/effect/animation/atdaybreak/daybreakstartfront_02.ani");
		createFristAnimationPooledObject(obj,
		"character/swordman/effect/animation/atdaybreak/hiteffecta_00.ani");
		createFristAnimationPooledObject(obj,
		"character/swordman/effect/animation/atdaybreak/hiteffectb_00.ani");
		createFristAnimationPooledObject(obj,
		"character/swordman/effect/animation/atdaybreak/hiteffectc_00.ani");
		createFristAnimationPooledObject(obj,
		"character/swordman/effect/animation/atdaybreak/hiteffectd_00.ani");
	}
}


function onEndState_DayBreak(obj,new_state)
{

	if (new_state != STATE_DAY_BREAK)
	{
		obj.setShowEquipmentLayer(ENUM_EQUIPMENTTYPE_WEAPON, true);
	}
}

function onSetState_DayBreak(obj, state, datas, isResetTimer)
{

	obj.sq_StopMove();
	local state = obj.sq_GetVectorData(datas, 0);
	obj.setSkillSubState(state);
	
	if (state == 0)
	{

		obj.getVar("soundRandom").clear_vector();
		obj.getVar("soundRandom").push_vector( sq_getRandom(0,100).tointeger() );
		//< 50 A
		//> 50 B

		if (obj.getVar("soundRandom").get_vector(0) < 50)
			playSoundTime(obj,"SW_DAYBREAK_01_A",100);
		else
			playSoundTime(obj,"SW_DAYBREAK_01_B",100);

		obj.setShowEquipmentLayer(ENUM_EQUIPMENTTYPE_WEAPON, false);
		obj.sq_SetCurrentAnimation( CUSTOM_ANI_DAY_BREAK_START );

		obj.getVar("flag").clear_vector();
		obj.getVar("flag").push_vector(0);
		obj.getVar("flag").push_vector(0);
		
		obj.getVar("dama2").clear_obj_vector();
		

	}else if (state == 1)
	{
		obj.sq_SetCurrentAnimation( CUSTOM_ANI_DAY_BREAK_MOVE );
		local objectManager = obj.getObjectManager();
		local xPos = objectManager.getFieldXPos(400, ENUM_DRAWLAYER_NORMAL);
		local yPos = objectManager.getFieldYPos(400, 0, ENUM_DRAWLAYER_NORMAL);
		obj.sq_SetfindNearLinearMovablePos(xPos,yPos,obj.getXPos(), obj.getYPos(), 10);

	}else if (state == 2)
	{
		obj.sq_SetCurrentAnimation( CUSTOM_ANI_DAY_BREAK_ATTACK );
		obj.sq_SetCurrentAttackInfo( ATTACKNIFO_DAY_BREAK_ATTACK );
		obj.getVar("flag").clear_vector();
		obj.getVar("flag").push_vector(0);
		obj.getVar("flag").push_vector(0);
		obj.getVar("flag").push_vector(0);
		obj.getVar("flag").push_vector(0);


		CreateDayBreakAttackBottomEffect(obj);
		
		local currentAttackInfo = sq_GetCurrentAttackInfo(obj);
		sq_SetCurrentAttackeHitStunTime(currentAttackInfo, 0);
	
	}else if (state == 3)
	{
		obj.sq_SetCurrentAnimation( CUSTOM_ANI_DAY_BREAK_END );
		obj.sq_SetCurrentAttackInfo(ATTACKINFO_DAY_BREAK_MULTING_ATTACK );

		local attackInfo = sq_GetCurrentAttackInfo(obj);
        local power = obj.sq_GetPowerWithPassive(SKILL_DAY_BREAK, STATE_DAY_BREAK, 0,-1,1.0);	 
        sq_SetCurrentAttackPower(attackInfo, power );	

		local currentAttackInfo = sq_GetCurrentAttackInfo(obj);
		sq_SetCurrentAttackeHitStunTime(currentAttackInfo, 0);

		obj.getVar("flag").clear_vector();
		obj.getVar("flag").push_vector(0);
		obj.getVar("flag").push_vector(0);
		obj.getVar("flag").push_vector(0);

		CreateDayBreakAttackEndEffect(obj);
		

	}
}

function onAttack_DayBreak(obj, damager, boundingBox, isStuck)
{

	local state = obj.getSkillSubState();
	if (state == 0)
	{
		if (damager.isObjectType(OBJECTTYPE_ACTIVE))
		{
		}
	}else if (state == 1)
	{
		if (damager.isObjectType(OBJECTTYPE_ACTIVE))
		{
		}
	}else if (state == 2)
	{
		createBladerHitEffectBlue(obj,damager);
		obj.getVar("dama2").push_obj_vector(damager);
	}
}

function onProc_DayBreak(obj)
{
	local state = obj.getSkillSubState();
	
	if (state == 0)
	{

		local pAni = obj.sq_GetCurrentAni();
		local frmIndex = obj.sq_GetCurrentFrameIndex(pAni);

		if (frmIndex >= 1 && obj.getVar("flag").get_vector(0) == 0)
		{
			obj.getVar("flag").set_vector(0,1);
			CreateDayBreakReadyEffect(obj);
		
		}
		if (frmIndex >= 4 && obj.getVar("flag").get_vector(1) == 0)
		{
			obj.getVar("flag").set_vector(1,1);
			CreateDayBreakReadyButtomEffect(obj);
		
		}
	
	}else if (state == 1)
	{
	
	}else if (state == 2)
	{
	
		local pAni = obj.sq_GetCurrentAni();
		local frmIndex = obj.sq_GetCurrentFrameIndex(pAni);

		if (frmIndex >= 9 && obj.getVar("flag").get_vector(0) == 0)
		{
			obj.getVar("flag").set_vector(0,1);
			CreateDayBreakAttackCoverEffect(obj);
			
		
		}
		
		if (frmIndex >= 10 && obj.getVar("flag").get_vector(1) == 0)
		{
			obj.getVar("flag").set_vector(1,1);
			obj.sq_setShakeOnlyMe(obj,10,120);
			
		
		}


		if (frmIndex >= 21 && obj.getVar("flag").get_vector(2) == 0)
		{
			obj.getVar("flag").set_vector(2,1);
			obj.sq_setShakeOnlyMe(obj,25,200);
			
		
		}

		if (frmIndex >= 13 && obj.getVar("flag").get_vector(3) == 0)
		{
			obj.getVar("flag").set_vector(3,1);

			if (obj.getVar("soundRandom").get_vector(0) < 50)
				playSoundTime(obj,"SW_DAYBREAK_03_A",100);
			else
				playSoundTime(obj,"SW_DAYBREAK_03_B",100);
		
		}



	
	}else if (state == 3)
	{

		local pAni = obj.sq_GetCurrentAni();
		local frmIndex = obj.sq_GetCurrentFrameIndex(pAni);

		if (frmIndex >= 16 && obj.getVar("flag").get_vector(0) == 0)
		{
			obj.getVar("flag").set_vector(0,1);
			obj.sq_setShakeOnlyMe(obj,10,500);
			CreateDayBreakAttackEndButtomEffect(obj);
			local countHit = 3;
			obj.setTimeEvent(0,500 / countHit,countHit,false);
			
		
		}

		if (frmIndex >= 28 && obj.getVar("flag").get_vector(1) == 0)
		{
			obj.getVar("flag").set_vector(1,1);

			if (obj.getVar("soundRandom").get_vector(0) < 50)
				playSoundTime(obj,"SW_DAYBREAK_04_A",100);
			else
				playSoundTime(obj,"SW_DAYBREAK_04_B",100);
		
		}

	}
	
}

function onTimeEvent_DayBreak(obj, timeEventIndex, timeEventCount)
{	

		local var = obj.getVar("dama2");  		
		local objectsSize = var.get_obj_vector_size();

		if (objectsSize > 0)
		{

			for(local i=0;i<objectsSize;++i)
			{
				local damager = var.get_obj_vector(i);
				if (damager)
				{
					sq_SendHitObjectPacketWithNoStuck(obj,damager,0,0, damager.getObjectHeight()/2 );
					createDayBreakHitEffectRandom4(obj,damager);
				}
			}
		}

}
function onEndCurrentAni_DayBreak(obj)
{
	local state = obj.getSkillSubState();
	if (state == 0)
	{

		local pIntVec = sq_GetGlobalIntVector();
		sq_IntVectorClear(pIntVec);
		sq_IntVectorPush(pIntVec, 1);			
		obj.addSetStatePacket(STATE_DAY_BREAK , pIntVec,  STATE_PRIORITY_USER, false, "");
	}else if (state == 1)
	{

		local pIntVec = sq_GetGlobalIntVector();
		sq_IntVectorClear(pIntVec);
		sq_IntVectorPush(pIntVec, 2);			
		obj.addSetStatePacket(STATE_DAY_BREAK , pIntVec,  STATE_PRIORITY_USER, false, "");
	}else if (state == 2)
	{

		local pIntVec = sq_GetGlobalIntVector();
		sq_IntVectorClear(pIntVec);
		sq_IntVectorPush(pIntVec, 3);			
		obj.addSetStatePacket(STATE_DAY_BREAK , pIntVec,  STATE_PRIORITY_USER, false, "");
	}
	
	
	else if (state == 3)
	{

		sq_SendMessage(obj,OBJECT_MESSAGE_INVINCIBLE,1,0);
		sq_PostDelayedMessage(obj,OBJECT_MESSAGE_INVINCIBLE,0,0,500 );
		obj.sq_AddSetStatePacket(STATE_STAND, STATE_PRIORITY_USER, false);
	}
}



function CreateDayBreakReadyEffect(obj)
{

	if(!obj || !sq_IsMyControlObject(obj) )
	return ;

	local ani = sq_CreateAnimation("",
	"character/swordman/effect/animation/atdaybreak/daybreakstartfront_02.ani");
	local pooledObj = sq_CreatePooledObject(ani,true);
//	pooledObj = sq_SetEnumDrawLayer(pooledObj, ENUM_DRAWLAYER_BOTTOM);
	local posX = sq_GetDistancePos(obj.getXPos(), obj.getDirection(), 0);
	pooledObj.setCurrentPos(posX  ,obj.getYPos() + 1,obj.getZPos() );
	pooledObj.setCurrentDirection(obj.getDirection());
	sq_AddObject(obj,pooledObj,2,false);	
	
	//sq_SetCustomRotate(pooledObj,sq_ToRadian(-135.0));	

}



function CreateDayBreakReadyButtomEffect(obj)
{

	if(!obj || !sq_IsMyControlObject(obj) )
	return ;

	local ani = sq_CreateAnimation("",
	"character/swordman/effect/animation/atdaybreak/daybreakstartbottom_00.ani");
	local pooledObj = sq_CreatePooledObject(ani,true);
	pooledObj = sq_SetEnumDrawLayer(pooledObj, ENUM_DRAWLAYER_BOTTOM);
	local posX = sq_GetDistancePos(obj.getXPos(), obj.getDirection(), 0);
	pooledObj.setCurrentPos(posX  ,obj.getYPos() + 1,obj.getZPos() );
	pooledObj.setCurrentDirection(obj.getDirection());
	sq_AddObject(obj,pooledObj,2,false);	
	
	//sq_SetCustomRotate(pooledObj,sq_ToRadian(-135.0));	

}


function CreateDayBreakAttackCoverEffect(obj)
{

	if(!obj || !sq_IsMyControlObject(obj) )
	return ;

	local ani = sq_CreateAnimation("",
	"character/swordman/effect/animation/atdaybreak/daybreakattackcover_01.ani");
	local pooledObj = sq_CreatePooledObject(ani,true);
	pooledObj = sq_SetEnumDrawLayer(pooledObj, ENUM_DRAWLAYER_COVER);
	local posX = sq_GetDistancePos(obj.getXPos(), obj.getDirection(), 0);
	pooledObj.setCurrentPos(posX  ,obj.getYPos() + 1,obj.getZPos() );
	pooledObj.setCurrentDirection(obj.getDirection());
	sq_AddObject(obj,pooledObj,2,false);	
	
	//sq_SetCustomRotate(pooledObj,sq_ToRadian(-135.0));	

}


function CreateDayBreakAttackBottomEffect(obj)
{

	if(!obj || !sq_IsMyControlObject(obj) )
	return ;

	local ani = sq_CreateAnimation("",
	"character/swordman/effect/animation/atdaybreak/daybreakattackbottom_00.ani");
	local pooledObj = sq_CreatePooledObject(ani,true);
	//pooledObj = sq_SetEnumDrawLayer(pooledObj, ENUM_DRAWLAYER_BOTTOM);
	local posX = sq_GetDistancePos(obj.getXPos(), obj.getDirection(), 0);
	pooledObj.setCurrentPos(posX  ,obj.getYPos() - 1,obj.getZPos() );
	pooledObj.setCurrentDirection(obj.getDirection());
	sq_AddObject(obj,pooledObj,2,false);	
	
	//sq_SetCustomRotate(pooledObj,sq_ToRadian(-135.0));	

}



function CreateDayBreakAttackEndEffect(obj)
{

	if(!obj || !sq_IsMyControlObject(obj) )
	return ;

	local ani = sq_CreateAnimation("",
	"character/swordman/effect/animation/atdaybreak/daybreakendcover_07.ani");
	local pooledObj = sq_CreatePooledObject(ani,true);
	pooledObj = sq_SetEnumDrawLayer(pooledObj, ENUM_DRAWLAYER_COVER);
	local posX = sq_GetDistancePos(obj.getXPos(), obj.getDirection(), 0);
	pooledObj.setCurrentPos(posX  ,obj.getYPos() + 1,obj.getZPos() );
	pooledObj.setCurrentDirection(obj.getDirection());
	sq_AddObject(obj,pooledObj,2,false);	
	
	//sq_SetCustomRotate(pooledObj,sq_ToRadian(-135.0));	

}


function CreateDayBreakAttackEndButtomEffect(obj)
{

	if(!obj || !sq_IsMyControlObject(obj) )
	return ;

	local ani = sq_CreateAnimation("",
	"character/swordman/effect/animation/atdaybreak/daybreakendbottom_00.ani");
	local pooledObj = sq_CreatePooledObject(ani,true);
	pooledObj = sq_SetEnumDrawLayer(pooledObj, ENUM_DRAWLAYER_BOTTOM);
	local posX = sq_GetDistancePos(obj.getXPos(), obj.getDirection(), 0);
	pooledObj.setCurrentPos(posX  ,obj.getYPos() + 1,obj.getZPos() );
	pooledObj.setCurrentDirection(obj.getDirection());
	sq_AddObject(obj,pooledObj,2,false);	
	
	//sq_SetCustomRotate(pooledObj,sq_ToRadian(-135.0));	

}



function createDayBreakHitEffectRandom4(obj,damager)
{
	if(!obj || !sq_IsMyControlObject(obj) )
	return ;

	local rand = sq_getRandom(0 , 100).tointeger();
	local ani;
	if (rand < 25)
		ani = sq_CreateAnimation("","character/swordman/effect/animation/atdaybreak/hiteffecta_00.ani");
	else if (rand < 50)
		ani = sq_CreateAnimation("","character/swordman/effect/animation/atdaybreak/hiteffectb_00.ani");
	else if (rand < 75)
		ani = sq_CreateAnimation("","character/swordman/effect/animation/atdaybreak/hiteffectc_00.ani");
	else if (rand <= 100)
		ani = sq_CreateAnimation("","character/swordman/effect/animation/atdaybreak/hiteffectd_00.ani");

	local pooledObj = sq_CreatePooledObject(ani,true);
	pooledObj.setCurrentPos(damager.getXPos() ,damager.getYPos() + 1,damager.getZPos() + damager.getObjectHeight()/2);
	pooledObj.setCurrentDirection(obj.getDirection());
	sq_AddObject(obj,pooledObj,2,false);	

	local rorate = obj.getCustomRotateAngle();
	sq_SetCustomRotate(pooledObj,rorate);	
}
